package com.chao.util;

import com.chao.error.BusinessException;
import com.chao.error.EnumError;
import org.springframework.util.DigestUtils;

import java.io.UnsupportedEncodingException;

/**
 * 工具类，只应该包含静态方法，通过类名调用
 * 构造方法私有
 */
public class CommonUtils {

    public static String md5(String value) throws BusinessException {
        try {
            return DigestUtils.md5DigestAsHex(value.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e){
            throw new BusinessException(EnumError.PARAMETER_VALIDATION_ERROR);
        }
    }

    private CommonUtils(){}
}
